package com.yonyougov.devops.cruxcisupport.user;

import com.yonyougov.devops.cruxcisupport.user.vo.UserMailVo;
import com.yonyougov.devops.cruxcisupport.user.vo.UserPageLikeDto;
import com.yonyougov.devops.cruxcisupport.user.vo.UserPageLikeVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.*;

/**
 * t_user数据层实现
 */
@Repository
public class UserDaoImpl extends BaseDaoImpl<UserEntity, BigInteger> implements UserDao {
    //<!--用户自定义代码开始-->
    private final SqlSessionTemplate sqlSessionTemplate;

    public UserDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public List<UserPageLikeVo> findByPageLike(UserPageLikeDto userPageLikeVoParams) {
        String statement = UserEntity.class.getName() + "Mapper.findUserPageLike";
        return sqlSessionTemplate.selectList(statement, userPageLikeVoParams);
    }

    @Override
    public int countByLikeUser(UserPageLikeDto userPageLikeReqVoParams) {
        String statement = UserEntity.class.getName() + "Mapper.countByLikeUser";
        return sqlSessionTemplate.selectOne(statement, userPageLikeReqVoParams);
    }

    @Override
    public String findPublicKeyByUserId(BigInteger userId) {
        String statement = UserEntity.class.getName() + "Mapper.getPublicKeyByUserId";
        return sqlSessionTemplate.selectOne(statement, userId);
    }

    @Override
    public List<UserEntity> findByIds(Set<BigInteger> userIds) {
        if (null == userIds || userIds.size() == 0) return new ArrayList<UserEntity>();
        String statement = UserEntity.class.getName() + "Mapper.findByIds";
        Map<String, Set<BigInteger>> map = new HashMap<>();
        map.put("list", userIds);
        return sqlSessionTemplate.selectList(statement, map);
    }

    @Override
    public List<UserMailVo> mailList() {
        String statement = UserEntity.class.getName() + "Mapper.mailList";
        return sqlSessionTemplate.selectList(statement);
    }

    @Override
    public UserEntity findByPrimaryKey(BigInteger id) {
        String statement = UserEntity.class.getName() + "Mapper.findByPrimaryKey";
        return sqlSessionTemplate.selectOne(statement, id);
    }

    //<!--用户自定义代码结束-->
}
